import { ExtractPropTypes } from 'vue'
import {
  FormRules,
  FormErrorTypeArray,
  FormLabelPositions,
  FormLabelPosition,
  FormLabelAlign,
  FormLabelAligns
} from './type'
import { validatorSizeValue } from '../../utils'

/**
 * props参数
 */
export const formProps = {
  /** 表单数据对象 */
  model: {
    type: Object,
    default: () => {
      return {}
    }
  },
  /** 校验规则 */
  rules: {
    type: Object,
    return: (): FormRules => {
      return {}
    }
  },
  /** 发生错误时的提示方式 */
  errorType: {
    type: [Array, String],
    default: (): FormErrorTypeArray => {
      return ['message', 'toast']
    }
  },
  /** 显示表单域下边框 */
  borderBottom: {
    type: Boolean,
    default: true
  },
  /** 标签显示的位置 */
  labelPosition: {
    type: String,
    default: (): FormLabelPosition => {
      return 'left'
    },
    validator: (value: FormLabelPosition) => {
      return FormLabelPositions.includes(value)
    }
  },
  /** 标签的宽度, 单位rpx */
  labelWidth: {
    type: [String, Number],
    default: '',
    validator: (value: string | number) => {
      return validatorSizeValue(value)
    }
  },
  /** 标签对齐方式 */
  labelAlign: {
    type: String,
    default: (): FormLabelAlign => {
      return 'left'
    },
    validator: (value: FormLabelAlign) => {
      return FormLabelAligns.includes(value)
    }
  }
}
export type FormProps = ExtractPropTypes<typeof formProps>
